<html>
<head><meta charset="utf-8"><title>using array ty instead of usize value · project-const-generics · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/index.html">project-const-generics</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/using.20array.20ty.20instead.20of.20usize.20value.html">using array ty instead of usize value</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="221208129"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/using%20array%20ty%20instead%20of%20usize%20value/near/221208129" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/using.20array.20ty.20instead.20of.20usize.20value.html#221208129">(Dec 30 2020 at 12:11)</a>:</h4>
<p>taken from <a href="https://github.com/rust-lang/rust/issues/80506">#80506</a></p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">combinations</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="mi">1</span><span class="o">..</span><span class="mi">2</span><span class="p">).</span><span class="n">combinations</span>::<span class="o">&lt;</span><span class="p">[</span><span class="kt">usize</span><span class="p">;</span><span class="w"> </span><span class="mi">2</span><span class="p">]</span><span class="o">&gt;</span><span class="p">();</span><span class="w"></span>
<span class="fm">assert_eq!</span><span class="p">(</span><span class="n">combinations</span><span class="p">.</span><span class="n">next</span><span class="p">(),</span><span class="w"> </span><span class="nb">None</span><span class="p">);</span><span class="w"></span>
</code></pre></div>
<p>where combinations has a <code>const N: usize</code> parameter.</p>



<a name="221208221"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/using%20array%20ty%20instead%20of%20usize%20value/near/221208221" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/using.20array.20ty.20instead.20of.20usize.20value.html#221208221">(Dec 30 2020 at 12:12)</a>:</h4>
<p>if we expect a const of type usize and find an array type we should suggest using the length of the array directly</p>



<a name="221208468"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/using%20array%20ty%20instead%20of%20usize%20value/near/221208468" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/using.20array.20ty.20instead.20of.20usize.20value.html#221208468">(Dec 30 2020 at 12:16)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="326189">@jknodt</span> <span class="user-mention" data-user-id="366818">@Pedro Mendes</span> <span class="user-mention" data-user-id="351972">@Ethan Brierley</span> <span class="user-mention" data-user-id="256313">@Hameer Abbasi</span> again <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>



<a name="221208585"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/using%20array%20ty%20instead%20of%20usize%20value/near/221208585" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/using.20array.20ty.20instead.20of.20usize.20value.html#221208585">(Dec 30 2020 at 12:19)</a>:</h4>
<p>for reference, we already do this for paths so that should be a good place to start looking <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=cc70eb84dc372f42cd2f9d8d0774ff7b">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=cc70eb84dc372f42cd2f9d8d0774ff7b</a></p>



<a name="221245018"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/using%20array%20ty%20instead%20of%20usize%20value/near/221245018" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> jknodt <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/using.20array.20ty.20instead.20of.20usize.20value.html#221245018">(Dec 30 2020 at 20:44)</a>:</h4>
<p>I'd be good w/ doing this if no one else wants to take it</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>